package com.develop.skwen.ourrules.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.develop.skwen.ourrules.basic.Presenter;
import com.develop.skwen.ourrules.basic.Vu;

/**
 * Created by skwen
 * on 18-4-24
 */

public abstract class BaseActivity<P extends Presenter,V extends Vu> extends AppCompatActivity {

    private V mV;

    public V getVu() {
        return mV;
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        onPrepare(savedInstanceState);
        try {
            mV = getVuClass().newInstance();
            mV.setActivity(this);
            mV.setPresenter(getPresenter());
            mV.init();
            setContentView(mV.getView());
            onBind();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    protected abstract Class<? extends V> getVuClass();

    protected abstract P getPresenter();

    protected void onPrepare(Bundle savedInstanceState){

    }

    protected void onBind(){

    }

}
